package loginTest;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginok")
public class Loginok extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String name=req.getParameter("username");
        if (name == null){
            name=req.getAttribute("name").toString();
        }

        User user1=new User();
        String[] hobby=req.getParameterValues("hobby");
        user1.hobbys=hobby;
        if (user1.hobbys!=null){
            for (int i=0;i<user1.hobbys.length;i++){
                resp.getWriter().write("<h1>爱好："+user1.hobbys[i]+"</h1></br>");
            }

        }
        resp.getWriter().write("<h1>欢迎你，"+name+"</h1>");
    }
}
